<template>
	<view class="">

		<!-- 1 -->
		<view class="" style="background: #ffd600;height: 30vh;">
			<view class="" style="text-align: center;border-top: 1px solid rgba(0, 0, 0, 0);">
				<view class="" style="font-size:33px;font-weight:700;color: #ffffff;margin-top:42rpx;">
					{{userInfo.Withdrawal?userInfo.Withdrawal.toFixed(2):0}}
				</view>
				<view class="" style="color: #ffffff;margin-top:5rpx;font-size: 14px;font-weight: 700;">
					当前可提现金额
				</view>
			</view>
		</view>

		<!-- 2 -->
		<view class=""
			style="width: 94%;margin:-150rpx auto 0;padding:42rpx 0;border-radius:15rpx;background-color: #fff;box-shadow:2px 2px 10px  5px #bebebe;">
			<view class="" style="margin: 0 25rpx;">
				提现金额<text v-if="baseFormData.limit!=0"  style="font-size: 28rpx;color: #ff585e;">(满{{baseFormData.limit}}可提现)</text>
			</view>
			<view class="" style="margin:20rpx 25rpx;display: flex;align-items: center;">
				<text style="font-size: 25px;">￥</text>
				<input class="uni-input" type="number" placeholder="请输入提现金额"
					style="color:#ffd600;font-weight: 600;font-size:20px;" v-model="money" />
			</view>
				<view class=""
					style="display: flex;align-items: center;justify-content: space-between;margin: 0 25rpx;color: #767676;font-size: 15px;font-weight: 700;">
					<view class="" @click="tx_type">
						提现账号:
					</view>
					<view class="" @click="tx_type" style="color: red;">
						{{formndata.zybao?formndata.zybao:''}}
					</view>
				</view>
			<view class="" style="margin: 20rpx;" @click="draw">
				<button style="background-color:#ff585e;color: #fff;">立即提现</button>
			</view>
		</view>

		<!-- 提现说明 -->
		<view class=""
			style="width: 94%;padding:20rpx 0;border-radius: 25rpx;background-color:#ffffff;box-shadow:2px 2px 10px  5px #dadada;margin:50rpx auto 0;">
			<view class="" style="margin: 0 25rpx;font-weight: 700;font-size: 14px;text-align: center;">
				提现说明
			</view>

			<view class="" style="margin: 25rpx;font-size: 15px;">
				<text v-if="baseFormData.explain">
					{{baseFormData.explain}}
			    </text>
			</view>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: null,
				tx_text: "微信", //默认显示文字
				type: ['微信', '支付宝', 'QQ'], //提现方式
				userInfo:{},
				baseFormData:{},
				formndata:{}
			}
		},
		onLoad() {
          this.getUser()
		  this.getbiao()
		  this.getsave()
		},
		methods: {
			async getsave(){
				const {data:res} = await this.$http.post('/nav/getsave',{})
				if(res.errCode==200 && res.data.zybao){
					this.formndata=res.data
				}
			},
			async getUser(){
				const {data : res} = await this.$http.post('/nav/getUser',{})
				if(res.errCode==200){
				 this.userInfo = res.data
				 uni.setStorageSync('user',res.data)
				}
						 
			},
			async getbiao(){
				 const {data : res} = await this.$http.post('/nav/getbiao',{})
				this.baseFormData=res.data
			},
			tx_type() {
				var that = this
				uni.showActionSheet({
					itemList: this.type,
					success: function(res) {
						that.tx_text = that.type[res.tapIndex]
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			async draw() {
				//点击提现的操作立即
				if(!this.formndata.zybao || !this.formndata){
					uni.showToast({
						icon: "none",
						title: '请先填写提现账号',
						success: () => {
						   uni.navigateTo({
						   	url:'/pages/tixian/tixian'
						   })	
						}
					})
					return
				}
				if(!this.money || this.money==0){
					uni.showToast({
						icon: "none",
						title: '请输入提现金额'
					})
					return
				}
				if(this.money>this.userInfo.Withdrawal){
					uni.showToast({
						icon: "none",
						title: '可提现金额不够，请重新输入'
					})
					this.money = null
					return
				} 
				if(this.money<this.baseFormData.limit){
					uni.showToast({
						icon: "none",
						title: '满'+this.baseFormData.limit+'才可体现奥'
					})
					this.money = null
					return
				}
				if(this.money && this.money<=this.userInfo.Withdrawal ){
					const {data:res} = await this.$http.post('/nav/addtixian',{price:this.money})
					if(res.errCode==200){
					   this.getUser()
						uni.showToast({
							icon: "none",
							title: '恭喜你,提现成功了'
						})
						this.money = null
					}
				    return
				}
				
				
				
				
			}
		}
	}
</script>

<style lang="scss">

</style>
